/*
 * @Author: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @Date: 2025-10-03 17:17:14
 * @LastEditors: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @LastEditTime: 2025-10-12 19:38:46
 * @FilePath: /GateServer/src/redis/redismgr.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#pragma  once
#include "../util/singleton.h"
#include "hiredis/hiredis.h"
#include <cstddef>
#include <memory>
#include "redisconnectionpool.h"
namespace Yizhi {
    class RedisMgr:public Singleton<RedisMgr>{
        friend class Singleton<RedisMgr>;

        public:
        ~RedisMgr();

        bool connect(const std::string &host,int port);
        bool Auth(const std::string &password);
        bool getvalue(const std::string &key,std::string &value);
        bool setvalue(const std::string &key,const std::string &value);
        bool del(const std::string &key);


        bool Rpush(const std::string &key,const std::string &value);
        bool Rpop(const std::string &key,std::string &value);
        bool Lpush(const std::string &key,const std::string &value);
        bool Lpop(const std::string &key,std::string &value);
        

        std::string HashGet(const std::string &key, const std::string &fields);

        bool Hashset(const std::string &,const std::string&,const  std::string);
        bool Hashset(const char*,const char* ,const char* ,size_t);

        bool Existskey(const std::string key);
        void close();


        public:

        private:
        RedisMgr();
        bool checkConnection();
        bool checkConnection(redisContext *con);
        bool m_connected;
        redisReply* m_reply;
        redisContext* m_connect;

        std::unique_ptr<RedisConnectionPool> m_conpool;
        
    };
}